package com.guangyuan.network.mvc.handler;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.guangyuan.network.constants.ProductGroupConstant;
import com.guangyuan.network.dataobject.Product;
import com.guangyuan.network.dataobject.ProductAttrRel;
import com.guangyuan.network.external.OperatorFactory;
import com.guangyuan.network.mvc.view.ContextAndTemplate;

public class ModifiedProductHandler extends AbstractHandler{
	
	private static final String NAME = "modifiedProduct.vm";
	
	@Override
	public ContextAndTemplate handler(HttpServletRequest request,
			HttpServletResponse response, ServletContext servletContext) {
		int product_id = Integer.parseInt(request.getParameter(ProductGroupConstant.product_id));
		
		Product product = OperatorFactory.getProductOper().getProductById(product_id);
		List<ProductAttrRel> attrs = OperatorFactory.getProductAttrRelOper().listProductAttrRelByProductId(product_id);
		
		ContextAndTemplate contextAndTemplate = getContextAndTemplate(NAME, request, response, servletContext);
		if(null != contextAndTemplate) {
			contextAndTemplate.getContext().put(ProductGroupConstant.product, product);
			contextAndTemplate.getContext().put(ProductGroupConstant.attrs, attrs);
			return contextAndTemplate;
		}
		return null;
	}

}
